package com.example.springboot.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@RestController
public class SpringbootDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootDemoApplication.class, args);
    }

    @Autowired
    RestTemplate restTemplate;

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @RequestMapping("/getkey")
    public void getkey() {
        String url = "http://localhost:8080/read?path=kv/myapp";
        ResponseEntity<Map> forEntity = restTemplate.getForEntity(url, Map.class);
        Map body1 = forEntity.getBody();
        System.out.println("getForEntity = " + body1);

        Map var = new HashMap<>();
        ResponseEntity<Map> postForEntity = restTemplate.postForEntity(url, null, Map.class);
        Map body = postForEntity.getBody();
        System.out.println("postForEntity = " + body);

    }

}
